import { lib, game, ui, get, ai, _status } from "../../noname.js";
import { } from "./character.js";
import { } from "./card.js";

game.import("extension", function (lib, game, ui, get, ai, _status) {
    return {
        name: "约会大作战",
        content: function (config, pack) {
            if (lib.rank) {
                //lib.rank.rarity.common.addArray([]);//普通：
                //lib.rank.rarity.junk.addArray([]);
                lib.rank.rarity.rare.addArray(["DALF_ItsukaKotori", "DALF_HonjouNia", "DALF_REN", "DALF_IsamiHijikata"]); //精品：五河琴里、本条二亚、莲、土方征美
                lib.rank.rarity.epic.addArray(["DALF_YatogamiTohka", "DALF_IzayoiMiku", "DALF_HimekawaYoshino", "DALF_TobiichiOrigami", "DALF_HimekawaYoshino_Umgekehrt", "DALF_HonjouNia_Umgekehrt", "DALF_TobiichiOrigami_Umgekehrt", "DALF_HonjouNia_SP"]); //传说：夜刀神十香、诱宵美九、氷芽川四糸乃、鸢一折纸、反转氷芽川四糸乃、反转本条二亚、反转鸢一折纸、SP本条二亚
                lib.rank.rarity.legend.addArray(["DALF_YamaiKguya&YamaiYuzuru", "DALF_KyonoNatsumi", "DALF_HoshimiyaMukuro", "DALF_TokisakiKurumi", "DALF_YatogamiTenka_Umgekehrt", "DALF_Mayuri"]); //史诗：八舞夕弦&八舞耶俱矢、七罪、星宫六喰、时崎狂三、反转夜刀神十香、万由里、
            }
            if (config.DALF_die_dub) {
                lib.skill._DALF_diedubs = {
                    trigger: { player: "dieBegin" },
                    priority: -Infinity,
                    forced: true,
                    unique: true,
                    content: function () {
                        "step 0"
                        var name = get.mode() == 'guozhan' ? player.name1 : player.name,
                            name2 = player.name2,
                            tags = lib.character[name][4],
                            audionum;
                        if (name2) tags = lib.character[name2][4];
                        if (tags && tags.length)
                            for (let i = 0; i < tags.length; i++)
                                if (tags[i].indexOf('dieAudio:') == 0)
                                    audionum = tags[i].slice(9);
                        if (audionum) {
                            let num = 1;
                            audionum = +audionum;
                            if (audionum > 1) num = get.rand(1, audionum);
                            game.playAudio('..', 'extension/audio/', '约会大作战', name + num);
                        } else {
                            game.playAudio('..', 'extension', '约会大作战/audio', name);
                            event.KJ = true;
                        }
                        if (name2 && tags2 && tags2.length) {
                            event.tags2 = tags2;
                            event.name = name2;
                        } else {
                            setTimeout(function () {
                                game.playAudio('..', 'extension/audio/', '约会大作战', name2);
                            }, 3000)
                            event.finish();
                        }
                        "step 1"
                        var audionum = undefined;
                        for (let i = 0; i < event.tags2.length; i++)
                            if (event.tags2[i].indexOf('dieAudio:') == 0)
                                audionum = event.tags2[i].slice(9);
                        if (audionum) {
                            let num = 1;
                            audionum = +audionum;
                            if (audionum > 1) num = get.rand(1, audionum);
                            if (event.KJ) game.playAudio('..', 'extension/audio/', '约会大作战', event.name + num);
                            else {
                                setTimeout(function () {
                                    game.playAudio('..', 'extension/audio/', '约会大作战', audioname);
                                }, 3000)
                            }
                        } else {
                            setTimeout(function () {
                                game.playAudio('..', 'extension/audio/', '约会大作战', event.name);
                            }, 3000)
                        }
                    },
                }
            }
            /*if(config.toKey){
                for(var i in lib.characterPack['DALF']) {
                    if(!["shen","key"].includes(lib.character[i][1])) lib.character[i][1]="key";
                }
            }*/

        },
        precontent: function (DALF) {
            //即时牌定义
            if (get.is.instantCard == undefined) {
                get.is.instantCard = function (obj) {
                    const types = ['equip', 'delay'];
                    return !types.includes(get.type(obj));
                }
            }
            game.addGroup("DALF_group", "约", "约战", { color: "#DA70D6" });
            //千幻皮肤
            window.DALF_import = function (f) {
                f(lib, game, ui, get, ai, _status);
            };
            lib.init.js(lib.assetURL + 'extension/约会大作战/DALF_skin.js');


            Object.assign(lib.element.player, {
                reacgnequipLink() {
                    let next = game.createEvent('reacgnequipLink');
                    next.player = this;
                    next.num = 0;
                    for (let i = 0; i < arguments.length; i++) {
                        if (get.itemtype(arguments[i]) == 'player') {
                            next.source = arguments[i];
                        }
                        else if (get.itemtype(arguments[i]) == 'cards') {
                            next.cards = arguments[i].slice(0);
                        }
                        else if (get.itemtype(arguments[i]) == 'card') {
                            next.cards = [arguments[i]];
                        }
                        else if (arguments[i] == 'notBySelf') {
                            next.notBySelf = true;
                        }
                    }
                    if (next.cards == undefined) _status.event.next.remove(next);
                    next.setContent('reacgnequipLink');
                    return next;
                },
                restoreReacgnequipLink() {
                    let next = game.createEvent('restoreReacgnequipLink');
                    next.player = this;
                    next.num = 0;
                    for (let i = 0; i < arguments.length; i++) {
                        if (get.itemtype(arguments[i]) == 'player') {
                            next.source = arguments[i];
                        }
                        else if (get.itemtype(arguments[i]) == 'cards') {
                            next.cards = arguments[i].slice(0);
                        }
                        else if (get.itemtype(arguments[i]) == 'card') {
                            next.cards = [arguments[i]];
                        }
                        else if (arguments[i] == 'notBySelf') {
                            next.notBySelf = true;
                        }
                    }
                    if (next.cards == undefined) _status.event.next.remove(next);
                    next.setContent('restoreReacgnequipLink');
                    return next;
                },
            })
            Object.assign(lib.element.content, {
                reacgnequipLink() {
                    'step 0'
                    for (var card of cards) {
                        if (get.position(card) == "e") player.removeEquipTrigger(card);
                        game.broadcastAll(function (card) {
                            card.addGaintag('reacgnequipLink');
                            card.storage.reacgnequipLink = true;
                        }, card);
                        game.log(player, '装备区内的', card, '被', source ? source : '', '#g横置');
                    }
                },
                restoreReacgnequipLink() {
                    'step 0'
                    for (var card of cards) {
                        if (get.position(card) == "e") {
                            var info = get.info(card);
                            if (info.skills) {
                                for (var i = 0; i < info.skills.length; i++) {
                                    player.addSkillTrigger(info.skills[i]);
                                }
                            }
                        }
                        game.broadcastAll(function (card) {
                            card.removeGaintag('reacgnequipLink');
                            card.storage.reacgnequipLink = false;
                        }, card);
                        game.log(player, '装备区内的', card, '解除', '#g横置');
                    }
                },
            });
            Object.assign(lib.get.is, {
                reacgnequipLinkCard(card, check) {
                    if (check && get.type(card) != 'equip') return false;
                    return card.storage && card.storage.reacgnequipLink;
                },
            })
        },
        help: {},
        config: {
            "DALF_die_dub": {
                name: "<b>阵亡配音</b>",
                intro: "开启后重启游戏后生效，本扩展角色阵亡时播放阵亡配音",
                init: false,
            },
            "skill_audio": {
                name: "<b>技能配音</b>",
                intro: "启用本扩展角色的技能配音",
                init: false,
            },
            /*
            "toKey":{
                "name":"统一势力所属",
                "init":false,
                "intro":"将该扩展的所有人物势力改为键"
            }
            */
        },
        package: {
            character: {
                character: {},
                translate: {},
            },
            card: {
                card: {},
                translate: {},
                list: [],
            },
            skill: {
                skill: {},
                translate: {},
            },
            intro: "《约会大作战》动漫同人的无名杀扩展。经过一次重置，大部分角色有所重铸或调整。代码层面已跟进到无名杀本体最新版。<br>理论上做出了联机的适配，但未经长时间测试，如联机请慎用。<br>角色特色鲜明，有优有缺，至少保证了几乎每个角色在一定水平线上、各自都有各自的爽点。代码兼容性尚可，支持大乱斗。<br>加载了千幻皮肤包（部分皮肤没有画师或出处是因为暂时没找到），受人气因素影响，皮肤数量有多有少，还请见谅。",
            author: "琉璃菠萝",
            diskURL: "",
            forumURL: "",
            version: "2022.12.10"
        },
        files: {
            "character": [],
            "card": [],
            "skill": []
        }
    }
})